# conftest.py (project root)
import sys
from pathlib import Path

import pytest
from httpx import ASGITransport, AsyncClient
from starlette.testclient import TestClient
from app import create_app

ROOT = Path(__file__).resolve().parent
SRC = ROOT / "src"
src_path = str(SRC.resolve())
if src_path not in sys.path:
    sys.path.insert(0, src_path)

app = create_app()


@pytest.fixture(scope="session")
def client():
    """全局共享一个 FastAPI 测试客户端"""
    with TestClient(app) as c:
        yield c


@pytest.fixture
async def async_client():
    transport = ASGITransport(app=app)
    async with AsyncClient(transport=transport, base_url="http://test") as c:
        yield c
